package com.fish.anne.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import com.fish.anne.webapp.formbean.FrontAutoSearch;
import com.fish.anne.webapp.util.DateTimeFormatUtil;

@Entity
@Table(name="auto" )
public class Auto extends BaseObject implements Serializable {
    private Long autoId;
    private String name;
    private byte engine;
    private String gearbox;
    private String brand;
    private Long brandId;
    private Long autoCount;
    private Long catId;
    private Long price;
    private Long weekendPrice;
    private Long holidayPrice;
    private Long insure;
    private Long levelOnePrice;
    private Long levelTwoPrice;
    private Long levelThreePrice;
    private Long placeId;
    private Long createTime;
    private Long lastModify;
    private boolean marketOn;
    private Long viewCount;
    private String defaultPic;
    private String smallPic;
    private String p1;
    private String p2;
    private String p3;
    private String p4;
    private String p5;
    private String whoIs;

    @Id   @GeneratedValue(strategy = GenerationType.AUTO)    
    public Long getAutoId() {
        return this.autoId;
    }
    
    public void setAutoId(Long autoId) {
        this.autoId = autoId;
    }
    
    @Column(name="name", nullable=false, length=100)
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @Column(name="engine", nullable=false)
    public byte getEngine() {
        return this.engine;
    }
    
    public void setEngine(byte engine) {
        this.engine = engine;
    }
    
    @Column(name="gearbox", nullable=false, length=5)
    public String getGearbox() {
        return this.gearbox;
    }
    
    public void setGearbox(String gearbox) {
        this.gearbox = gearbox;
    }
    
    @Column(name="brand", nullable=false, length=100)
    public String getBrand() {
        return this.brand;
    }
    
    public void setBrand(String brand) {
        this.brand = brand;
    }
    
    @Column(name="brand_id", nullable=false)
    public Long getBrandId() {
        return this.brandId;
    }
    
    public void setBrandId(Long brandId) {
        this.brandId = brandId;
    }
    
    @Column(name="auto_count", nullable=false)
    public Long getAutoCount() {
        return this.autoCount;
    }
    
    public void setAutoCount(Long autoCount) {
        this.autoCount = autoCount;
    }
    
    @Column(name="cat_id", nullable=false)
    public Long getCatId() {
        return this.catId;
    }
    
    public void setCatId(Long catId) {
        this.catId = catId;
    }
    
    @Column(name="price", nullable=false)
    public Long getPrice() {
        return this.price;
    }
    
    public void setPrice(Long price) {
        this.price = price;
    }
    
    @Column(name="weekend_price", nullable=false)
    public Long getWeekendPrice() {
        return this.weekendPrice;
    }
    
    public void setWeekendPrice(Long weekendPrice) {
        this.weekendPrice = weekendPrice;
    }
    
    @Column(name="holiday_price", nullable=false)
    public Long getHolidayPrice() {
        return this.holidayPrice;
    }
    
    public void setHolidayPrice(Long holidayPrice) {
        this.holidayPrice = holidayPrice;
    }
    
    @Column(name="insure", nullable=false)
    public Long getInsure() {
        return this.insure;
    }
    
    public void setInsure(Long insure) {
        this.insure = insure;
    }
    
    @Column(name="level_one_price", nullable=false)
    public Long getLevelOnePrice() {
        return this.levelOnePrice;
    }
    
    public void setLevelOnePrice(Long levelOnePrice) {
        this.levelOnePrice = levelOnePrice;
    }
    
    @Column(name="level_two_price", nullable=false)
    public Long getLevelTwoPrice() {
        return this.levelTwoPrice;
    }
    
    public void setLevelTwoPrice(Long levelTwoPrice) {
        this.levelTwoPrice = levelTwoPrice;
    }
    
    @Column(name="level_three_price", nullable=false)
    public Long getLevelThreePrice() {
        return this.levelThreePrice;
    }
    
    public void setLevelThreePrice(Long levelThreePrice) {
        this.levelThreePrice = levelThreePrice;
    }
    
    @Column(name="place_id", nullable=false)
    public Long getPlaceId() {
        return this.placeId;
    }
    
    public void setPlaceId(Long placeId) {
        this.placeId = placeId;
    }
    
    @Column(name="create_time", nullable=false)
    public Long getCreateTime() {
        return this.createTime;
    }
    
    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }
    
    @Column(name="last_modify", nullable=false)
    public Long getLastModify() {
        return this.lastModify;
    }
    
    public void setLastModify(Long lastModify) {
        this.lastModify = lastModify;
    }
    
    @Column(name="market_on", nullable=false)
    public boolean isMarketOn() {
        return this.marketOn;
    }
    
    public void setMarketOn(boolean marketOn) {
        this.marketOn = marketOn;
    }
    
    @Column(name="view_count", nullable=false)
    public Long getViewCount() {
        return this.viewCount;
    }
    
    public void setViewCount(Long viewCount) {
        this.viewCount = viewCount;
    }
    
    @Column(name="default_pic", nullable=false)
    public String getDefaultPic() {
        return this.defaultPic;
    }
    
    public void setDefaultPic(String defaultPic) {
        this.defaultPic = defaultPic;
    }
    
    @Column(name="small_pic", nullable=false)
    public String getSmallPic() {
        return this.smallPic;
    }
    
    public void setSmallPic(String smallPic) {
        this.smallPic = smallPic;
    }
    
    @Column(name="p_1", nullable=false, length=100)
    public String getP1() {
        return this.p1;
    }
    
    public void setP1(String p1) {
        this.p1 = p1;
    }
    
    @Column(name="p_2", nullable=false, length=100)
    public String getP2() {
        return this.p2;
    }
    
    public void setP2(String p2) {
        this.p2 = p2;
    }
    
    @Column(name="p_3", nullable=false, length=100)
    public String getP3() {
        return this.p3;
    }
    
    public void setP3(String p3) {
        this.p3 = p3;
    }
    
    @Column(name="p_4", nullable=false, length=100)
    public String getP4() {
        return this.p4;
    }
    
    public void setP4(String p4) {
        this.p4 = p4;
    }
    
    @Column(name="p_5", nullable=false, length=100)
    public String getP5() {
        return this.p5;
    }
    
    public void setP5(String p5) {
        this.p5 = p5;
    }
    
    @Column(name="who_is", nullable=false)
    public String getWhoIs() {
        return this.whoIs;
    }
    
    public void setWhoIs(String whoIs) {
        this.whoIs = whoIs;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Auto pojo = (Auto) o;

        if (name != null ? !name.equals(pojo.name) : pojo.name != null) return false;
         if (gearbox != null ? !gearbox.equals(pojo.gearbox) : pojo.gearbox != null) return false;
        if (brand != null ? !brand.equals(pojo.brand) : pojo.brand != null) return false;
        if (brandId != null ? !brandId.equals(pojo.brandId) : pojo.brandId != null) return false;
        if (autoCount != null ? !autoCount.equals(pojo.autoCount) : pojo.autoCount != null) return false;
        if (catId != null ? !catId.equals(pojo.catId) : pojo.catId != null) return false;
        if (price != null ? !price.equals(pojo.price) : pojo.price != null) return false;
        if (weekendPrice != null ? !weekendPrice.equals(pojo.weekendPrice) : pojo.weekendPrice != null) return false;
        if (holidayPrice != null ? !holidayPrice.equals(pojo.holidayPrice) : pojo.holidayPrice != null) return false;
        if (insure != null ? !insure.equals(pojo.insure) : pojo.insure != null) return false;
        if (levelOnePrice != null ? !levelOnePrice.equals(pojo.levelOnePrice) : pojo.levelOnePrice != null) return false;
        if (levelTwoPrice != null ? !levelTwoPrice.equals(pojo.levelTwoPrice) : pojo.levelTwoPrice != null) return false;
        if (levelThreePrice != null ? !levelThreePrice.equals(pojo.levelThreePrice) : pojo.levelThreePrice != null) return false;
        if (placeId != null ? !placeId.equals(pojo.placeId) : pojo.placeId != null) return false;
        if (createTime != null ? !createTime.equals(pojo.createTime) : pojo.createTime != null) return false;
        if (lastModify != null ? !lastModify.equals(pojo.lastModify) : pojo.lastModify != null) return false;
        if (marketOn != pojo.marketOn) return false;
        if (viewCount != null ? !viewCount.equals(pojo.viewCount) : pojo.viewCount != null) return false;
        if (defaultPic != null ? !defaultPic.equals(pojo.defaultPic) : pojo.defaultPic != null) return false;
        if (smallPic != null ? !smallPic.equals(pojo.smallPic) : pojo.smallPic != null) return false;
        if (p1 != null ? !p1.equals(pojo.p1) : pojo.p1 != null) return false;
        if (p2 != null ? !p2.equals(pojo.p2) : pojo.p2 != null) return false;
        if (p3 != null ? !p3.equals(pojo.p3) : pojo.p3 != null) return false;
        if (p4 != null ? !p4.equals(pojo.p4) : pojo.p4 != null) return false;
        if (p5 != null ? !p5.equals(pojo.p5) : pojo.p5 != null) return false;
        if (whoIs != null ? !whoIs.equals(pojo.whoIs) : pojo.whoIs != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (name != null ? name.hashCode() : 0);
         result = 31 * result + (gearbox != null ? gearbox.hashCode() : 0);
        result = 31 * result + (brand != null ? brand.hashCode() : 0);
        result = 31 * result + (brandId != null ? brandId.hashCode() : 0);
        result = 31 * result + (autoCount != null ? autoCount.hashCode() : 0);
        result = 31 * result + (catId != null ? catId.hashCode() : 0);
        result = 31 * result + (price != null ? price.hashCode() : 0);
        result = 31 * result + (weekendPrice != null ? weekendPrice.hashCode() : 0);
        result = 31 * result + (holidayPrice != null ? holidayPrice.hashCode() : 0);
        result = 31 * result + (insure != null ? insure.hashCode() : 0);
        result = 31 * result + (levelOnePrice != null ? levelOnePrice.hashCode() : 0);
        result = 31 * result + (levelTwoPrice != null ? levelTwoPrice.hashCode() : 0);
        result = 31 * result + (levelThreePrice != null ? levelThreePrice.hashCode() : 0);
        result = 31 * result + (placeId != null ? placeId.hashCode() : 0);
        result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
        result = 31 * result + (lastModify != null ? lastModify.hashCode() : 0);
        result = 31 * result + (marketOn ? 1 : 0);
        result = 31 * result + (viewCount != null ? viewCount.hashCode() : 0);
        result = 31 * result + (defaultPic != null ? defaultPic.hashCode() : 0);
        result = 31 * result + (smallPic != null ? smallPic.hashCode() : 0);
        result = 31 * result + (p1 != null ? p1.hashCode() : 0);
        result = 31 * result + (p2 != null ? p2.hashCode() : 0);
        result = 31 * result + (p3 != null ? p3.hashCode() : 0);
        result = 31 * result + (p4 != null ? p4.hashCode() : 0);
        result = 31 * result + (p5 != null ? p5.hashCode() : 0);
        result = 31 * result + (whoIs != null ? whoIs.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("autoId").append("='").append(getAutoId()).append("', ");
        sb.append("name").append("='").append(getName()).append("', ");
        sb.append("engine").append("='").append(getEngine()).append("', ");
        sb.append("gearbox").append("='").append(getGearbox()).append("', ");
        sb.append("brand").append("='").append(getBrand()).append("', ");
        sb.append("brandId").append("='").append(getBrandId()).append("', ");
        sb.append("autoCount").append("='").append(getAutoCount()).append("', ");
        sb.append("catId").append("='").append(getCatId()).append("', ");
        sb.append("price").append("='").append(getPrice()).append("', ");
        sb.append("weekendPrice").append("='").append(getWeekendPrice()).append("', ");
        sb.append("holidayPrice").append("='").append(getHolidayPrice()).append("', ");
        sb.append("insure").append("='").append(getInsure()).append("', ");
        sb.append("levelOnePrice").append("='").append(getLevelOnePrice()).append("', ");
        sb.append("levelTwoPrice").append("='").append(getLevelTwoPrice()).append("', ");
        sb.append("levelThreePrice").append("='").append(getLevelThreePrice()).append("', ");
        sb.append("placeId").append("='").append(getPlaceId()).append("', ");
        sb.append("createTime").append("='").append(getCreateTime()).append("', ");
        sb.append("lastModify").append("='").append(getLastModify()).append("', ");
        sb.append("marketOn").append("='").append(isMarketOn()).append("', ");
        sb.append("viewCount").append("='").append(getViewCount()).append("', ");
        sb.append("defaultPic").append("='").append(getDefaultPic()).append("', ");
        sb.append("smallPic").append("='").append(getSmallPic()).append("', ");
        sb.append("p1").append("='").append(getP1()).append("', ");
        sb.append("p2").append("='").append(getP2()).append("', ");
        sb.append("p3").append("='").append(getP3()).append("', ");
        sb.append("p4").append("='").append(getP4()).append("', ");
        sb.append("p5").append("='").append(getP5()).append("', ");
        sb.append("whoIs").append("='").append(getWhoIs()).append("'");
        sb.append("]");
      
        return sb.toString();
    }
    
    private FrontAutoSearch frontAutoSearch;
    
    
    
    public FrontAutoSearch getFrontAutoSearch() {
		return frontAutoSearch;
	}

	public void setFrontAutoSearch(FrontAutoSearch frontAutoSearch) {
		this.frontAutoSearch = frontAutoSearch; 
	}
    
    /**
     *   
     * @param begin
     * @param end
     * @return
     * @throws Exception 
     */
    public Integer getTotalAmount() throws Exception{
    	int price = this.getPrice().intValue();
    	int wprice =this.getWeekendPrice().intValue();
    	
    	Date begin =  DateTimeFormatUtil.convertStringToDate(this.getFrontAutoSearch().getBeginDate() ,DateTimeFormatUtil.YEAR_MONTH_DAY_TEMPLATE_1);
    	Date end =   DateTimeFormatUtil.convertStringToDate(this.getFrontAutoSearch().getEndDate() ,DateTimeFormatUtil.YEAR_MONTH_DAY_TEMPLATE_1);
    	int sum = 0;
    	while(DateTimeFormatUtil.greatOrEqualByDate( end, begin)){
    		boolean week = DateTimeFormatUtil.isWeekEnd(begin);
    		if(week){
    			sum +=wprice;
    		}else{
    			sum +=price;
    		}
    		begin = DateTimeFormatUtil.addTimeByDays(begin, 1);
    	}
    	
    	
    	return sum;
    }

}
